import time


class Data():
    def __init__(self):
        self.scg_time = []
        self.acceleration_x_value = []
        self.acceleration_y_value = []
        self.acceleration_z_value = []
        self.angular_velocity_x_value = []
        self.angular_velocity_y_value = []
        self.angular_velocity_z_value = []
        self.ppg_time = []
        self.ppg_value = []

        self.heart_rate = 0

        self.mode = 0

        self.timer = 0

        self.ppg_threshold = 0
        self.ppg_error_num = 0
        self.ppg_index = []

        self.scg_acc_z_threshold = 0
        self.scg_acc_z_error_num = 0
        self.scg_acc_z_index = []

        self.scg_ang_z_threshold = 0
        self.scg_ang_z_error_num = 0
        self.scg_ang_z_index = []

        self.scg_ang_x_threshold = 0
        self.scg_ang_x_error_num = 0
        self.scg_ang_x_index = []

        self.scg_final_index = []
        self.scg_final_error_num = 0

        self.ptt = []

        self.high_a = -41.7447
        self.high_b = -86.1102

        self.low_a = -24.2293
        self.low_b = -40.5892

        self.hypertension = 0
        self.hypotension = 0

        self.user_name = ''


    def collect_scg_data(self, data):
        if data == [] or self.mode == 2:
            return
        self.scg_time.append(time.time())
        self.acceleration_x_value.append(data[0][0])
        self.acceleration_y_value.append(data[0][1])
        self.acceleration_z_value.append(data[0][2])
        self.angular_velocity_x_value.append(data[1][0])
        self.angular_velocity_y_value.append(data[1][1])
        self.angular_velocity_z_value.append(data[1][2])
        # 普通模式，实时读取数据且删除
        if self.mode == 0 and len(self.scg_time) > 1000:
            del self.scg_time[0]
            del self.acceleration_x_value[0]
            del self.acceleration_y_value[0]
            del self.acceleration_z_value[0]
            del self.angular_velocity_x_value[0]
            del self.angular_velocity_y_value[0]
            del self.angular_velocity_z_value[0]

    def collect_ppg_data(self, ppg):
        if ppg == None or self.mode == 2:
            return
        self.ppg_time.append(time.time())
        self.ppg_value.append(ppg)
        if self.mode == 0 and len(self.ppg_value) > 1000:
            del self.ppg_time[0]
            del self.ppg_value[0]

    def delete_data(self):
        self.scg_time = []
        self.acceleration_x_value = []
        self.acceleration_y_value = []
        self.acceleration_z_value = []
        self.angular_velocity_x_value = []
        self.angular_velocity_y_value = []
        self.angular_velocity_z_value = []
        self.ppg_time = []
        self.ppg_value = []
